<?php
/**
 * Created by IntelliJ IDEA.
 * User: luo
 * Date: 18-3-16
 * Time: 上午9:17
 */

namespace app\tools;

use Yii;
use yii\log\FileTarget;

class Tool
{
    /**
     * @param $message
     * @param string $target
     * @throws \yii\base\InvalidConfigException
     * @throws \yii\log\LogRuntimeException
     */
    public static function log($message, $target = 'app.log'){
        if(is_array($message) or is_object($message)){
            $message = var_export($message, true);
        }

        $log = new FileTarget();
        $log->logFile = Yii::$app->getRuntimePath() . '/logs/'.$target;
        $log->messages[] = [
            $message,
            1,
            'application',
            time()
        ];
        $log->export();
    }

}